package com.xiguaji.tiktok.task.aweme;

import com.xiguaji.boot.eventbus.EventBusTemplate;
import com.xiguaji.tiktok.task.aweme.event.SaveRecommendAwemeEventListener;
import com.xiguaji.tiktok.task.core.ScheduleTemplate;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AwemeTask {
    @Autowired
    EventBusTemplate eventBusTemplate;
    @Autowired
    ScheduleTemplate scheduleTemplate;
    @Autowired
    ESAwemeService esAwemeService;
    @Autowired
    AwemeService awemeService;
    /**
     * 获取推荐流，目标是获取粉丝数量大于1W的播主
     *
     * @param param
     * @return
     */
    @XxlJob("recommendAwemeHandler")
    public ReturnT<String> recommendAwemeHandler(String param) {
        var saveRecommendAwemeEvent = new SaveRecommendAwemeEventListener.SaveRecommendAwemeEvent();
        eventBusTemplate.post(saveRecommendAwemeEvent);
        return ReturnT.SUCCESS;
    }


    /**
     * 每月月底删除ES旧的aweme数据
     * @param param
     * @return
     */
    @XxlJob("deleteESAwemeIndexHandler")
    public ReturnT<String> deleteESAwemeIndexHandler(String param) {
        esAwemeService.deleteAwemeIndex();
        awemeService.deleteUserCollectionAweme();
        return ReturnT.SUCCESS;
    }

    /**
     * 每月月底创建下个月的aweme索引
     * @param param
     * @return
     */
    @XxlJob("createESAwemeIndexHandler")
    public ReturnT<String> createESAwemeIndexHandler(String param) {
        esAwemeService.createAwemeIndex();
        return ReturnT.SUCCESS;
    }

//    /**
//     * 视频关键字保存
//     *
//     * @param param
//     * @return
//     */
//    @XxlJob("refreshAwemeKeywordEvent")
//    public ReturnT<String> refreshAwemeKeywordEvent(String param) {
//        var refreshAwemeKeywordEvent = new RefreshAwemeKeywordEventListener.RefreshAwemeKeywordEvent();
//        // scheduleTemplate.run("FetchFollowingHandlerPool", 5, 5000, () -> eventBusTemplate.post(refreshAwemeKeywordEvent));
//        eventBusTemplate.post(refreshAwemeKeywordEvent);
//        return ReturnT.SUCCESS;
//    }

//    /**
//     * 视频关键字保存
//     *
//     * @param param
//     * @return
//     */
//    @XxlJob("refreshAwemeKeywordForTagsIsNullEvent")
//    public ReturnT<String> refreshAwemeKeywordForTagsIsNullEvent(String param) {
//        SaveAwemeKeywordEventListener.SaveAwemeKeywordEvent saveAwemeKeywordEvent = new SaveAwemeKeywordEventListener.SaveAwemeKeywordEvent();
//        eventBusTemplate.post(saveAwemeKeywordEvent);
//        return ReturnT.SUCCESS;
//    }
}


